package org.example.controller;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController

public class UserController {
    @Autowired
    private RestTemplate restTemplate;
    @RequestMapping("/user/order/query/{id}")
    @CircuitBreaker(name="aaa",fallbackMethod = "myFallback")
    public String queryOrder(@PathVariable  int id){
        return this.restTemplate.getForObject("http://micro-eureka-order/order/" + id, String.class);
    }

    @RequestMapping("/user/query/{id}")
    public String queryUser(@PathVariable  int id){
        return "用户信息: "+id;
    }

    public  String myFallback(Throwable t){
        return  "服务不可用，Ex:" + t.getMessage();
    }
}
